package com.wennimei.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wennimei.dao.UserDAO;
import com.wennimei.domain.User;

@Service
public class UserService {
    @Autowired
    private UserDAO userDAO;

    public void insertUser(String regType, String renrenId, String weixinId,
            String sinawbId, String country, String province, String city,
            String sex) {

        User user = null;
        if (regType.equals(User.REG_TYPE_WEIXIN))
            user = this.userDAO.getWeixinUser(weixinId);
        else if (regType.equals(User.REG_TYPE_RENREN))
            user = this.userDAO.getRenrenUser(renrenId);
        else
            user = this.userDAO.getSinawbUser(sinawbId);

        if (null == user) {
            user = new User(regType, renrenId, weixinId, sinawbId, country,
                    province, city, sex);
            this.userDAO.insert(user);
        }
    }
}
